/*对token状态进行管理*/
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
  state:{
    token: '',
    refresh_token: '',
    loginInfo: {
      username: '',
      password: ''
    }
  },
  mutations:{
    set_token(state, token) {
      state.token = token;
      sessionStorage.token = token
    },
    set_refresh_token(state, refresh_token){
      state.refresh_token = refresh_token;
      sessionStorage.refresh_token = refresh_token
    },
    del_token(state) {
      state.token = '';
      sessionStorage.removeItem('token')
    },
    del_refresh_token(state){
      state.refresh_token = '';
      sessionStorage.removeItem('refresh_token')
    },
    set_loginInfo(state, loginInfo){
      state.loginInfo.username = loginInfo.username;
      state.loginInfo.password = loginInfo.password;
    }
  }
});

export default store;
